const {
	Service
} = require("uni-cloud-router");
const {
	result_success,
	result_error
} = require('http-result-modle');
const db = uniCloud.database();
const $ = db.command.aggregate;
const uidObj = require('uni-id');
module.exports = class ComboService extends(
	Service
) {

	async list(event) {
		let uid = '';
		if (this.ctx.event.uniIdToken) {
			// 已登录，获取当前登录 uid
			const userRes = await uidObj.checkToken(this.ctx.event.uniIdToken);
			if (userRes.code == 0) {
				uid = userRes.uid;
			}
		}
		if (!uid) {
			response.msg = '当前未登录'
			return response;
		}
		const comboRes = await this.db.collection('wmz-goods-combo').get()
		return result_success(comboRes.data);
	}
	async detail(event) {
		let uid = '';
		if (this.ctx.event.uniIdToken) {
			// 已登录，获取当前登录 uid
			const userRes = await uidObj.checkToken(this.ctx.event.uniIdToken);
			if (userRes.code == 0) {
				uid = userRes.uid;
			}
		}
		if (!uid) {
			response.msg = '当前未登录'
			return response;
		}
		let _id=event.data._id
		const comboRes = await this.db.collection('wmz-goods-combo').doc(_id).get()
		return result_success(comboRes.data[0]);
	}
};